package springboot.doMain;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * wx_user
 */
@Data
@NoArgsConstructor
public class WxUser implements Serializable {
	private Integer id;
	
	private String userId;
	
	private String name;
	
	private String department;
	
	private String position;
	
	private String mobile;
	
	private Integer gender;
	
	private static final long serialVersionUID = 1L;
	
	
	public static List<Integer> ArrayStringToInt(String s) {
		if (s==null) return null;
		if (s.equals("")) return null;
		s = s.replace("[", "");
		s = s.replace("]", "");
		s = s.replace(" ", "");
		String[] split = s.split(",");
		List<String> strings = new ArrayList<>(Arrays.asList(split));
		List<Integer> integerList = new ArrayList<>();
		strings.forEach(s1 -> integerList.add(Integer.parseInt(s1)));
		return integerList;
	}
	
	
	public WxUser(JSONObject parseObject) {
		if (parseObject == null) {
			return;
		}
		this.userId = parseObject.getString("userid");
		this.name = parseObject.getString("name");
		this.department = parseObject.getString("department");
		this.position = parseObject.getString("position");
		this.mobile = parseObject.getString("mobile");
		this.gender = parseObject.getInteger("gender");
	}
	
	public WxUser(String s) {
		if (s == null) {
			return;
		}
		try {
			JSONObject jsonObject = JSONObject.parseObject(s);
			this.userId = jsonObject.getString("userid");
			this.name = jsonObject.getString("name");
			this.department = jsonObject.getString("department");
			this.position = jsonObject.getString("position");
			this.mobile = jsonObject.getString("mobile");
			this.gender = jsonObject.getInteger("gender");
		} catch (Exception e) {
			System.err.print("转换WxUser失败");
			e.printStackTrace();
		}
	}
}
